package com.finger.forest.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.finger.forest.R;
import com.finger.forest.model.GridUserModel;
import com.finger.forest.model.UserManagerModel;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.List;

/**
 * @author sy
 * @date 2021/2/5
 * @desc
 */
public class UserManagerAdapter extends BaseQuickAdapter<GridUserModel, BaseViewHolder> {
    public UserManagerAdapter(int layoutResId, @Nullable List<GridUserModel> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GridUserModel item) {
        RoundedImageView rivUserHead = helper.getView(R.id.rivUserHead);
        Glide.with(mContext)
                .load(item.getHeadPortraitRul())
                .placeholder(R.mipmap.header)
                .into(rivUserHead);

        helper.setText(R.id.tvRealName, item.getName());
        helper.setText(R.id.tvUserId, "编号:" + item.getId());
        helper.setText(R.id.tvUserName, "用户名:" + item.getName());
        TextView tvDefault = helper.getView(R.id.tvDefault);
        //tvDefault.setText("默认通道:" + item.getValidFlag());
        tvDefault.setText("");

        CheckBox cbUser = helper.getView(R.id.cbUser);

        cbUser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                cbUser.setChecked(isChecked);
                item.setSelect(isChecked);
                onUserManagerSelectListener.selectListener();
            }
        });

        if (item.isShow()) {
            tvDefault.setVisibility(View.GONE);
            cbUser.setVisibility(View.VISIBLE);
        } else {
            tvDefault.setVisibility(View.VISIBLE);
            cbUser.setVisibility(View.GONE);
        }
    }

    public OnUserManagerSelectListener onUserManagerSelectListener;

    public void setOnUserManagerSelectListener(OnUserManagerSelectListener onUserManagerSelectListener) {
        this.onUserManagerSelectListener = onUserManagerSelectListener;
    }

    public interface OnUserManagerSelectListener {
        void selectListener();
    }
}
